package example.mydemo.service;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DemoService extends Activity {

	private Button btnStart, btnStop;
	//private PendingIntent mToast;
	//private Intent i;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_demo_service);
		
		
		
		btnStart = (Button) findViewById(R.id.btnStartApp);
		btnStop = (Button) findViewById(R.id.btnStopApp);
		btnStart.setOnClickListener(Listener);
		btnStop.setOnClickListener(Listener);
		
	}
	
	private OnClickListener Listener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btnStartApp:
				startService(new Intent(DemoService.this, MyService.class));
				//mToast = PendingIntent.getService(getApplicationContext(), 0, i, 0);				
				break;
				
			case R.id.btnStopApp:
				stopService(new Intent(DemoService.this, MyService.class));
				break;

			}
		}
	};
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.demo, menu);
		return true;
	}
	
	@Override
	protected void onDestroy(){
		super.onDestroy();
		if(!MyService.music.isPlaying()){
			stopService(new Intent(DemoService.this, MyService.class));
		}
	}

}
